﻿using System;
using System.Net;
using System.Runtime.Serialization;

namespace Airport
{
    [DataContract]
    public class Suggestion : ISuggestion, IEquatable<Suggestion>
    {
        private int _priority;
        private Plane _suggestionPlane;
        private Route _suggestionRoute;
        private bool _isAccepted;

        public Suggestion()
            : this(-1, new Plane(), new Route())
        {
        }

        public Suggestion(int priority, Plane plane, Route route)
        {
            _priority = priority;
            _suggestionPlane = plane;
            _suggestionRoute = route;
            _isAccepted = false;
        }

        [DataMember]
        public int Priority
        {
            get
            {
                return _priority;
            }

            set
            {
                if (_priority != value)
                {
                    _priority = value;
                }
            }
        }

        [DataMember]
        public Plane SuggestionPlane
        {
            get
            {
                return _suggestionPlane;
            }

            set
            {
                if (_suggestionPlane != value)
                {
                    _suggestionPlane = value;
                }
            }
        }

        [DataMember]
        public Route SuggestionRoute
        {
            get
            {
                return _suggestionRoute;
            }

            set
            {
                if (_suggestionRoute != value)
                {
                    _suggestionRoute = value;
                }
            }
        }

        [DataMember]
        public bool IsAccepted
        {
            get
            {
                return _isAccepted;
            }

            set
            {
                if (_isAccepted != value)
                {
                    _isAccepted = value;
                }
            }
        }

        public bool Equals(Suggestion other)
        {            
            if (other == null)
            {
                return false;
            }

            if (!_suggestionPlane.Equals(other._suggestionPlane))
            {
                return false;
            }

            if (!_suggestionRoute.Equals(other._suggestionRoute))
            {
                return false;
            }

            return true;
        }

        public static bool operator ==(Suggestion a, Suggestion b)
        {            
            if (System.Object.ReferenceEquals(a, b))
            {
                return true;
            }

            if (((object)a == null) || ((object)b == null))
            {
                return false;
            }

            return a.Equals(b);            
        }

        public static bool operator !=(Suggestion a, Suggestion b)
        {
            return !(a == b);
        }

        public override string ToString()
        {
            string planeString, routeString;

            if (_suggestionPlane == null)
            {
                planeString = "null";
            }
            else
            {
                planeString = _suggestionPlane.ToString();
            }

            if (_suggestionRoute == null)
            {
                routeString = "null";
            }
            else
            {
                routeString = _suggestionRoute.ToString();
            }

            return planeString + "; " + routeString;
        }
    }
}
